#include <iostream>

using namespace std;

struct Node{
    int data;
    Node *next;
};

void creat(int length,Node **head,int *a);
Node* dele(int m,Node *head,int *len);
void print(Node *head);

int main(){
    int n;
    int a[100];
    int m;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cin>>m;
    Node *head;
    int len=0;
    creat(n,&head,a);
    head=dele(m,head,&len);
    cout<<len<<endl;
    print(head);

    return 0;
}

void creat(int length,Node **head,int *a){
    *head=new Node;
    Node *p=*head;
    for(int i=0;i<length-1;i++){
        p->data=a[i];
        p->next=new Node;
        p=p->next;
    }
    p->data=a[length-1];
    p->next=NULL;
}

Node* dele(int m,Node *head,int *len){
    while(head->data==m)
        head=head->next;
    Node *pre=head,*p=head->next;
    (*len)++;
    while(p!=NULL){
        if(p->data==m){
            pre->next=p->next;
            p=p->next;
        }
        else{
            pre=pre->next;
            p=p->next;
            (*len)++;
        }
    }
    return head;
}

void print(Node *head){
    Node *p=head;
    while(p!=NULL){
        cout<<p->data<<" ";
        p=p->next;
    }
    cout<<endl;
}
